package com.code.gen.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.code.gen.bean.bo.CodeGenProperties;
import com.code.gen.bean.bo.CodeGenPropertiesSystem;
import com.code.gen.bean.bo.file.CodeGenFieldProperties;
import com.code.gen.bean.bo.file.CodeGenFileProperties;
import com.code.gen.bean.bo.template.CodeGenTemplate;
import com.code.gen.constant.CodeGenConstant;
import com.code.gen.enums.ECodeGenFieldEquals;
import com.code.gen.enums.ECodeGenHtmlType;
import com.code.gen.enums.ECodeGenQueryType;
import com.code.gen.enums.ECodeGenTemplateQueryType;
import com.sojson.base.impl.Base;
import com.sojson.base.impl.BaseBean;
import com.sojson.base.impl.BaseLogicDelBean;
import com.sojson.enums.EEnvironmentUserType;
import com.sojson.enums.core.EGeneralYesNo;
import com.sojson.util.DateUtil;
import com.sojson.util.StringUtil;

import lombok.Data;

/**
 * 代码生成条件工具类
 * 
 * @author liu
 * @date 2022-08-10
 */
@Data
public class CodeGenConditionMethodUtil {

    private CodeGenProperties properties;
    private CodeGenFileProperties file;
    private CodeGenTemplate template;

    public CodeGenConditionMethodUtil(CodeGenProperties properties, CodeGenFileProperties file,
        CodeGenTemplate template) {
        this.properties = properties;
        this.file = file;
        this.template = template;
    }

    /**
     * 判断ID是否存在
     * 
     * @return
     */
    public boolean idIsExists() {
        return getFile().getExistId();
    }

    /**
     * 判断编号是否存在
     * 
     * @return
     */
    public boolean serialNumberIsExists() {
        return getFile().getExistSerialNumber();
    }

    /**
     * 判断删除标志是否存在
     * 
     * @return
     */
    public boolean delIsExists() {
        return getFile().getExistDel();
    }

    /**
     * 判断ID和删除标志是否存在
     * 
     * @return
     */
    public boolean idDelIsExists() {
        CodeGenFileProperties file = getFile();
        return file.getExistId() && file.getExistDel();
    }

    /**
     * 判断编号和删除标志是否存在
     * 
     * @return
     */
    public boolean serialNumberDelIsExists() {
        CodeGenFileProperties file = getFile();
        return file.getExistSerialNumber() && file.getExistDel();
    }

    /**
     * 判断编号和删除标志是否存在
     * 
     * @return
     */
    public boolean createTimeIsExists() {
        CodeGenFileProperties file = getFile();
        List<CodeGenFieldProperties> fileFeild = file.getFileFeild();
        for (CodeGenFieldProperties feild : fileFeild) {
            if (feild.getFieldNameX().equals(properties.getSystem().getCreateTime())) {
                return true;
            }
        }

        return false;
    }

    /**
     * 获取entity父类
     * 
     * @return
     */
    public String getEntityFather() {
        if (file.getExistDel()) {
            return BaseLogicDelBean.class.getSimpleName();
        } else {
            List<CodeGenFieldProperties> feilds = file.getFileFeild();
            for (CodeGenFieldProperties feild : feilds) {
                if (feild.getFieldNameX().equals(properties.getSystem().getCreateBy())) {
                    return BaseBean.class.getSimpleName();
                }
            }
            return Base.class.getSimpleName();
        }
    }

    /**
     * 获取entity父类的包路径
     * 
     * @return
     */
    public String getEntityFatherPackage() {
        String pack = null;
        if (file.getExistDel()) {
            pack = getClassPackage(BaseLogicDelBean.class);
        } else {
            List<CodeGenFieldProperties> feilds = file.getFileFeild();
            for (CodeGenFieldProperties feild : feilds) {
                if (feild.getFieldNameX().equals(properties.getSystem().getCreateBy())) {
                    pack = getClassPackage(BaseBean.class);
                    break;
                }
            }
            if (StringUtil.isBlank(pack)) {
                pack = getClassPackage(Base.class);
            }
        }
        if (StringUtil.isBlank(pack)) {
            return "";
        }
        return "import " + pack + ";";
    }

    /**
     * 获取entity字段的包路径
     * 
     * @return
     */
    public String getEntityFieldPackage() {
        StringBuilder builder = new StringBuilder();
        ECodeGenFieldEquals[] values = ECodeGenFieldEquals.values();
        List<String> noFields = properties.getSystem().getNoFields();

        List<CodeGenFieldProperties> feilds = file.getFileFeild();
        ECodeGenTemplateQueryType type = template.getQueryType();
        if (type == ECodeGenTemplateQueryType.QUERY) {
            CodeGenPropertiesSystem system = properties.getSystem();
            List<String> queryFields = system.getQueryFields();
            List<String> queryNoFields = system.getQueryNoFields();
            if (queryFields.size() > 0) {
                for (CodeGenFieldProperties feild : feilds) {
                    if (queryFields.contains(feild.getFieldNameDatabaseD())) {
                        for (ECodeGenFieldEquals fieldEquals : values) {
                            if (fieldEquals.getJavaBase().equals(feild.getFieldJavaType())) {
                                String packageName = fieldEquals.getPackageName();
                                if (StringUtil.isNotBlank(packageName)) {
                                    builder.append("import " + fieldEquals.getPackageName() + ";").append("\n");
                                    break;
                                }
                            }
                        }
                    }
                }
            } else if (queryNoFields.size() > 0) {
                for (CodeGenFieldProperties feild : feilds) {
                    if (!queryNoFields.contains(feild.getFieldNameDatabaseD())) {
                        for (ECodeGenFieldEquals fieldEquals : values) {
                            if (fieldEquals.getJavaBase().equals(feild.getFieldJavaType())) {
                                String packageName = fieldEquals.getPackageName();
                                if (StringUtil.isNotBlank(packageName)) {
                                    builder.append("import " + fieldEquals.getPackageName() + ";").append("\n");
                                    break;
                                }
                            }
                        }
                    }
                }
            } else {
                for (CodeGenFieldProperties feild : feilds) {
                    for (ECodeGenFieldEquals fieldEquals : values) {
                        if (fieldEquals.getJavaBase().equals(feild.getFieldJavaType())) {
                            String packageName = fieldEquals.getPackageName();
                            if (StringUtil.isNotBlank(packageName)) {
                                builder.append("import " + fieldEquals.getPackageName() + ";").append("\n");
                                break;
                            }
                        }
                    }
                }
            }
        } else if (type == ECodeGenTemplateQueryType.RESULT) {
            List<CodeGenFieldProperties> arrayList = new ArrayList<>();
            CodeGenPropertiesSystem system = properties.getSystem();
            List<String> resultFields = system.getResultFields();
            List<String> resultNoFields = system.getResultNoFields();
            if (resultFields.size() > 0) {
                for (CodeGenFieldProperties feild : feilds) {
                    if (resultFields.contains(feild.getFieldNameDatabaseD())) {
                        arrayList.add(feild);
                        for (ECodeGenFieldEquals fieldEquals : values) {
                            if (fieldEquals.getJavaBase().equals(feild.getFieldJavaType())) {
                                String packageName = fieldEquals.getPackageName();
                                if (StringUtil.isNotBlank(packageName)) {
                                    builder.append("import " + fieldEquals.getPackageName() + ";").append("\n");
                                    break;
                                }
                            }
                        }
                    }
                }
            } else if (resultNoFields.size() > 0) {
                for (CodeGenFieldProperties feild : feilds) {
                    if (!resultNoFields.contains(feild.getFieldNameDatabaseD())) {
                        arrayList.add(feild);
                        for (ECodeGenFieldEquals fieldEquals : values) {
                            if (fieldEquals.getJavaBase().equals(feild.getFieldJavaType())) {
                                String packageName = fieldEquals.getPackageName();
                                if (StringUtil.isNotBlank(packageName)) {
                                    builder.append("import " + fieldEquals.getPackageName() + ";").append("\n");
                                    break;
                                }
                            }
                        }
                    }
                }
            } else {
                for (CodeGenFieldProperties feild : feilds) {
                    arrayList.add(feild);
                    for (ECodeGenFieldEquals fieldEquals : values) {
                        if (fieldEquals.getJavaBase().equals(feild.getFieldJavaType())) {
                            String packageName = fieldEquals.getPackageName();
                            if (StringUtil.isNotBlank(packageName)) {
                                builder.append("import " + fieldEquals.getPackageName() + ";").append("\n");
                                break;
                            }
                        }
                    }
                }
            }
            for (CodeGenFieldProperties feild : feilds) {
                if (EGeneralYesNo.YES.getCode() == feild.getIsList()) {
                    builder.append("import com.sojson.annotation.Excel;").append("\n");
                }
            }
        } else {
            for (CodeGenFieldProperties feild : feilds) {
                if (!noFields.contains(feild.getFieldNameDatabaseD())) {
                    for (ECodeGenFieldEquals fieldEquals : values) {
                        if (fieldEquals.getJavaBase().equals(feild.getFieldJavaType())) {
                            String packageName = fieldEquals.getPackageName();
                            if (StringUtil.isNotBlank(packageName)) {
                                builder.append("import " + fieldEquals.getPackageName() + ";").append("\n");
                                break;
                            }
                        }
                    }
                }
            }
        }

        return builder.toString();
    }

    /**
     * 获取entity表名注解
     * 
     * @return
     */
    public String getEntityTableNameAnno() {
        boolean tableAnno = properties.getSystem().isDatabaseTableAnno();
        String tableName = file.getTableName();

        if (tableAnno) {
            return "@TableName(\"" + tableName + "\")";
        } else {
            return "";
        }
    }

    /**
     * 获取entity表名注解的包路径
     * 
     * @return
     */
    public String getEntityTableNameAnnoPackage() {
        boolean tableAnno = properties.getSystem().isDatabaseTableAnno();

        if (tableAnno) {
            return "import com.baomidou.mybatisplus.annotation.TableName;";
        } else {
            return "";
        }
    }

    /**
     * 获取xml的查询语句
     * 
     * @return
     */
    public String getQueryTypeXml() {
        ECodeGenTemplateQueryType queryTypeTemplate = template.getQueryType();
        StringBuilder content = new StringBuilder();
        StringBuilder stringBuilder = null;
        String zwf = null;
        List<CodeGenFieldProperties> feilds = file.getFileFeild();
        for (CodeGenFieldProperties feild : feilds) {
            if (queryTypeTemplate == ECodeGenTemplateQueryType.QUERY) {
                CodeGenPropertiesSystem system = properties.getSystem();
                List<String> queryFields = system.getQueryFields();
                List<String> queryNoFields = system.getQueryNoFields();
                if (queryFields.size() > 0) {
                    if (!queryFields.contains(feild.getFieldNameDatabaseD())) {
                        continue;
                    }
                } else if (queryNoFields.size() > 0) {
                    if (queryNoFields.contains(feild.getFieldNameDatabaseD())) {
                        continue;
                    }
                }
            } else if (queryTypeTemplate == ECodeGenTemplateQueryType.RESULT) {
                CodeGenPropertiesSystem system = properties.getSystem();
                List<String> resultFields = system.getResultFields();
                List<String> resultNoFields = system.getResultNoFields();
                if (resultFields.size() > 0) {
                    if (!resultFields.contains(feild.getFieldNameDatabaseD())) {
                        continue;
                    }
                } else if (resultNoFields.size() > 0) {
                    if (resultNoFields.contains(feild.getFieldNameDatabaseD())) {
                        continue;
                    }
                }
            }
            stringBuilder = new StringBuilder();
            String queryType = feild.getQueryType();
            if (queryType.equals(ECodeGenQueryType.EQ.getCode())) {
                zwf = "=";
            } else if (queryType.equals(ECodeGenQueryType.NE.getCode())) {
                zwf = "!=";
            } else if (queryType.equals(ECodeGenQueryType.GT.getCode())) {
                zwf = "<![CDATA[>]]>";
            } else if (queryType.equals(ECodeGenQueryType.GTE.getCode())) {
                zwf = "<![CDATA[>=]]>";
            } else if (queryType.equals(ECodeGenQueryType.LT.getCode())) {
                zwf = "<![CDATA[<]]>";
            } else if (queryType.equals(ECodeGenQueryType.LTE.getCode())) {
                zwf = "<![CDATA[<=]]>";
            } else if (queryType.equals(ECodeGenQueryType.LIKE.getCode())) {
                zwf = "LIKE";
            } else if (queryType.equals(ECodeGenQueryType.BETWEEN.getCode())) {

            } else {

            }

            if (queryType.equals(ECodeGenQueryType.BETWEEN.getCode())) {
                stringBuilder.append("        <if test=\"begin~fieldNameD~ != null and over~fieldNameD~ != null\">");
                stringBuilder.append(StringUtil.ENTER);
                stringBuilder.append("            AND ~fieldNameDbD~ BETWEEN");
                stringBuilder.append(StringUtil.ENTER);
                stringBuilder.append(
                    "            #{begin~fieldNameD~, jdbcType=~databaseFieldTypeXml~} AND #{over~fieldNameD~, jdbcType=~databaseFieldTypeXml~}");
                stringBuilder.append(StringUtil.ENTER);
            } else if (queryType.equals(ECodeGenQueryType.LIKE.getCode())) {
                stringBuilder.append("        <if test=\"~fieldNameX~ != null\">");
                stringBuilder.append(StringUtil.ENTER);
                stringBuilder.append(
                    "            AND INSTR(~fieldNameDbD~, #{~fieldNameX~, jdbcType=~databaseFieldTypeXml~}) > 0");
                stringBuilder.append(StringUtil.ENTER);
            } else {
                stringBuilder.append("        <if test=\"~fieldNameX~ != null\">");
                stringBuilder.append(StringUtil.ENTER);
                stringBuilder.append("            AND ~fieldNameDbD~ ");
                stringBuilder.append(zwf);
                stringBuilder.append(" #{~fieldNameX~, jdbcType=~databaseFieldTypeXml~}");
                stringBuilder.append(StringUtil.ENTER);
            }
            stringBuilder.append("        </if>");
            content.append(CodeGenReadTemplate.replacePropertyPlaceholder(stringBuilder.toString(), feild));
            content.append(StringUtil.ENTER);
        }
        return content.toString();
    }

    /**
     * 获取xml的查询语句
     * 
     * @return
     */
    public String getBetweenListParamDto() {
        StringBuilder content = new StringBuilder();
        StringBuilder stringBuilder = null;
        List<CodeGenFieldProperties> feilds = file.getFileFeild();
        for (CodeGenFieldProperties feild : feilds) {
            if (ECodeGenQueryType.BETWEEN.getCode().equals(feild.getQueryType())) {
                stringBuilder = new StringBuilder();
                stringBuilder.append("    /** 开始~fieldComment~ */");
                stringBuilder.append(StringUtil.ENTER);
                stringBuilder.append("    @ApiModelProperty(\"开始~fieldComment~\")");
                stringBuilder.append(StringUtil.ENTER);
                stringBuilder.append("    private ~fieldType~ begin~fieldNameD~;");
                stringBuilder.append(StringUtil.ENTER);
                stringBuilder.append("    /** 结束~fieldComment~ */");
                stringBuilder.append(StringUtil.ENTER);
                stringBuilder.append("    @ApiModelProperty(\"结束~fieldComment~\")");
                stringBuilder.append(StringUtil.ENTER);
                stringBuilder.append("    private ~fieldType~ over~fieldNameD~;");
                content.append(CodeGenReadTemplate.replacePropertyPlaceholder(stringBuilder.toString(), feild));
                content.append(StringUtil.ENTER);
            }
        }
        return content.toString();
    }

    /**
     * 获取xml的排序字段
     * 
     * @return
     */
    public String getSortXml() {
        StringBuilder content = new StringBuilder();
        boolean exists = false;
        CodeGenPropertiesSystem system = properties.getSystem();
        List<CodeGenFieldProperties> feilds = file.getFileFeild();
        for (CodeGenFieldProperties feild : feilds) {
            if (system.getSort().contains(feild.getFieldNameDatabaseD())) {
                exists = true;
                content.append(feild.getFieldNameDatabaseD());
                content.append(", ");
            }
        }

        if (exists) {
            return "        ORDER BY " + content.substring(0, content.length() - 2);
        } else {
            return content.toString();
        }
    }

    /**
     * 获取添加菜单的sql语句
     * 
     * @return
     */
    public String getSqlInsertMenu() {
        StringBuilder content = new StringBuilder();
        String idOne = IdWorker.getIdStr();
        String idTwo = IdWorker.getIdStr();
        String creatrById = properties.getSystem().getCreatrById();
        String now = DateUtil.nowString();
        String field =
            "INSERT INTO `~databaseName~`.`sys_menu`(`id`, `name`, `parent_id`, `sort_num`, `path`, `component`, `is_frame`, `is_cache`, `environment`, `type`, `content_type`, `content_msg`, `visible`, `status`, `perms`, `icon`, `remark`, `create_by`, `create_time`, `update_by`, `update_time`)";

        // 模块
        // 字段
        content.append(field);
        content.append(StringUtil.ENTER);
        // 值
        content.append("VALUES ('");
        // ID
        content.append(idOne);
        content.append("'");
        // 名称
        content.append(", '");
        content.append("~classComment~模块");
        content.append("'");
        // 上级菜单ID
        content.append(", '");
        content.append(file.getParentMenuId());
        content.append("'");
        // 排序
        content.append(", 100");
        // 请求地址
        content.append(", '");
        String moduleName = file.getModuleName();
        String d = ".";
        if (moduleName.contains(d)) {
            moduleName = moduleName.substring(0, moduleName.indexOf("."));
        }
        content.append(moduleName);
        content.append("'");
        // 路由地址
        content.append(", NULL");
        // 是否为外链（1是2否）
        content.append(", 2");
        // 是否缓存（1缓存 2不缓存）
        content.append(", 1");
        // 菜单环境(web_admin:后台管理员,web_merchant:后台商户,app_user:App用户,xcx_user:小程序用户)
        content.append(", '");
        content.append(EEnvironmentUserType.WEB_ADMIN.getCode());
        content.append("'");
        // 菜单类型（1目录 2菜单 3按钮）
        content.append(", 1");
        // 内容类型(1:链接,2:商品列表类型ID,3:商品详情ID,4:文章ID,5:活动ID)
        content.append(", 1");
        // 内容信息(商品列表为商品类型ID,商品详情为商品ID,文章为文章ID,活动为活动ID)
        content.append(", NULL");
        // 菜单状态（1显示 2隐藏）
        content.append(", 1");
        // 菜单状态（1正常 2停用）
        content.append(", 1");
        // 权限标识
        content.append(", NULL");
        // 菜单图标
        content.append(", '");
        content.append("server");
        content.append("'");
        // 其他
        content.append(", NULL, '" + creatrById + "', '" + now + "', '" + creatrById + "', '" + now + "'");
        // 结束
        content.append(");");
        content.append(StringUtil.ENTER);

        // 菜单
        // 字段
        content.append(field);
        content.append(StringUtil.ENTER);
        // 值
        content.append("VALUES ('");
        // ID
        content.append(idTwo);
        content.append("'");
        // 名称
        content.append(", '");
        content.append("~classComment~管理");
        content.append("'");
        // 上级菜单ID
        content.append(", '");
        content.append(idOne);
        content.append("'");
        // 排序
        content.append(", 1");
        // 请求地址
        content.append(", '");
        moduleName = file.getModuleName();
        if (moduleName.contains(d)) {
            moduleName = moduleName.substring(moduleName.indexOf(".") + 1);
        }
        content.append(moduleName);
        content.append("'");
        // 路由地址
        content.append(", '");
        content.append(file.getModuleName().replace(".", "/"));
        content.append("'");
        // 是否为外链（1是2否）
        content.append(", 2");
        // 是否缓存（1缓存 2不缓存）
        content.append(", 1");
        // 菜单环境(web_admin:后台管理员,web_merchant:后台商户,app_user:App用户,xcx_user:小程序用户)
        content.append(", '");
        content.append(EEnvironmentUserType.WEB_ADMIN.getCode());
        content.append("'");
        // 菜单类型（1目录 2菜单 3按钮）
        content.append(", 2");
        // 内容类型(1:链接,2:商品列表类型ID,3:商品详情ID,4:文章ID,5:活动ID)
        content.append(", 1");
        // 内容信息(商品列表为商品类型ID,商品详情为商品ID,文章为文章ID,活动为活动ID)
        content.append(", NULL");
        // 菜单状态（1显示 2隐藏）
        content.append(", 1");
        // 菜单状态（1正常 2停用）
        content.append(", 1");
        // 权限标识
        content.append(", '");
        content.append("~controllerUrl~/list~controllerSuffixShow~");
        content.append("'");
        // 菜单图标
        content.append(", '");
        content.append("server");
        content.append("'");
        // 其他
        content.append(", NULL, '" + creatrById + "', '" + now + "', '" + creatrById + "', '" + now + "'");
        // 结束
        content.append(");");
        content.append(StringUtil.ENTER);

        // 按钮
        // 添加按钮
        // 字段
        content.append(field);
        content.append(StringUtil.ENTER);
        // 值
        content.append("VALUES ('");
        // ID
        content.append(IdWorker.getIdStr());
        content.append("'");
        // 名称
        content.append(", '");
        content.append("~classComment~新增");
        content.append("'");
        // 上级菜单ID
        content.append(", '");
        content.append(idTwo);
        content.append("'");
        // 排序
        content.append(", 1");
        // 请求地址
        content.append(", NULL");
        // 路由地址
        content.append(", NULL");
        // 是否为外链（1是2否）
        content.append(", 2");
        // 是否缓存（1缓存 2不缓存）
        content.append(", 1");
        // 菜单环境(web_admin:后台管理员,web_merchant:后台商户,app_user:App用户,xcx_user:小程序用户)
        content.append(", '");
        content.append(EEnvironmentUserType.WEB_ADMIN.getCode());
        content.append("'");
        // 菜单类型（1目录 2菜单 3按钮）
        content.append(", 3");
        // 内容类型(1:链接,2:商品列表类型ID,3:商品详情ID,4:文章ID,5:活动ID)
        content.append(", NULL");
        // 内容信息(商品列表为商品类型ID,商品详情为商品ID,文章为文章ID,活动为活动ID)
        content.append(", NULL");
        // 菜单状态（1显示 2隐藏）
        content.append(", 1");
        // 菜单状态（1正常 2停用）
        content.append(", 1");
        // 权限标识
        content.append(", '");
        content.append("~controllerUrl~/save~controllerSuffixDo~");
        content.append("'");
        // 菜单图标
        content.append(", '");
        content.append("#");
        content.append("'");
        // 其他
        content.append(", NULL, '" + creatrById + "', '" + now + "', '" + creatrById + "', '" + now + "'");
        // 结束
        content.append(");");
        content.append(StringUtil.ENTER);

        // 修改按钮
        if (file.getExistId()) {
            // 字段
            content.append(field);
            content.append(StringUtil.ENTER);
            // 值
            content.append("VALUES ('");
            // ID
            content.append(IdWorker.getIdStr());
            content.append("'");
            // 名称
            content.append(", '");
            content.append("~classComment~修改");
            content.append("'");
            // 上级菜单ID
            content.append(", '");
            content.append(idTwo);
            content.append("'");
            // 排序
            content.append(", 2");
            // 请求地址
            content.append(", NULL");
            // 路由地址
            content.append(", NULL");
            // 是否为外链（1是2否）
            content.append(", 2");
            // 是否缓存（1缓存 2不缓存）
            content.append(", 1");
            // 菜单环境(web_admin:后台管理员,web_merchant:后台商户,app_user:App用户,xcx_user:小程序用户)
            content.append(", '");
            content.append(EEnvironmentUserType.WEB_ADMIN.getCode());
            content.append("'");
            // 菜单类型（1目录 2菜单 3按钮）
            content.append(", 3");
            // 内容类型(1:链接,2:商品列表类型ID,3:商品详情ID,4:文章ID,5:活动ID)
            content.append(", NULL");
            // 内容信息(商品列表为商品类型ID,商品详情为商品ID,文章为文章ID,活动为活动ID)
            content.append(", NULL");
            // 菜单状态（1显示 2隐藏）
            content.append(", 1");
            // 菜单状态（1正常 2停用）
            content.append(", 1");
            // 权限标识
            content.append(", '");
            content.append("~controllerUrl~/updateById~controllerSuffixDo~");
            content.append("'");
            // 菜单图标
            content.append(", '");
            content.append("#");
            content.append("'");
            // 其他
            content.append(", NULL, '" + creatrById + "', '" + now + "', '" + creatrById + "', '" + now + "'");
            // 结束
            content.append(");");
            content.append(StringUtil.ENTER);
        }

        // 导出按钮
        // 字段
        content.append(field);
        content.append(StringUtil.ENTER);
        // 值
        content.append("VALUES ('");
        // ID
        content.append(IdWorker.getIdStr());
        content.append("'");
        // 名称
        content.append(", '");
        content.append("~classComment~导出");
        content.append("'");
        // 上级菜单ID
        content.append(", '");
        content.append(idTwo);
        content.append("'");
        // 排序
        content.append(", 3");
        // 请求地址
        content.append(", NULL");
        // 路由地址
        content.append(", NULL");
        // 是否为外链（1是2否）
        content.append(", 2");
        // 是否缓存（1缓存 2不缓存）
        content.append(", 1");
        // 菜单环境(web_admin:后台管理员,web_merchant:后台商户,app_user:App用户,xcx_user:小程序用户)
        content.append(", '");
        content.append(EEnvironmentUserType.WEB_ADMIN.getCode());
        content.append("'");
        // 菜单类型（1目录 2菜单 3按钮）
        content.append(", 3");
        // 内容类型(1:链接,2:商品列表类型ID,3:商品详情ID,4:文章ID,5:活动ID)
        content.append(", NULL");
        // 内容信息(商品列表为商品类型ID,商品详情为商品ID,文章为文章ID,活动为活动ID)
        content.append(", NULL");
        // 菜单状态（1显示 2隐藏）
        content.append(", 1");
        // 菜单状态（1正常 2停用）
        content.append(", 1");
        // 权限标识
        content.append(", '");
        content.append("~controllerUrl~/export");
        content.append("'");
        // 菜单图标
        content.append(", '");
        content.append("#");
        content.append("'");
        // 其他
        content.append(", NULL, '" + creatrById + "', '" + now + "', '" + creatrById + "', '" + now + "'");
        // 结束
        content.append(");");
        content.append(StringUtil.ENTER);

        // 详情按钮
        if (file.getExistId()) {
            // 字段
            content.append(field);
            content.append(StringUtil.ENTER);
            // 值
            content.append("VALUES ('");
            // ID
            content.append(IdWorker.getIdStr());
            content.append("'");
            // 名称
            content.append(", '");
            content.append("~classComment~查询");
            content.append("'");
            // 上级菜单ID
            content.append(", '");
            content.append(idTwo);
            content.append("'");
            // 排序
            content.append(", 4");
            // 请求地址
            content.append(", NULL");
            // 路由地址
            content.append(", NULL");
            // 是否为外链（1是2否）
            content.append(", 2");
            // 是否缓存（1缓存 2不缓存）
            content.append(", 1");
            // 菜单环境(web_admin:后台管理员,web_merchant:后台商户,app_user:App用户,xcx_user:小程序用户)
            content.append(", '");
            content.append(EEnvironmentUserType.WEB_ADMIN.getCode());
            content.append("'");
            // 菜单类型（1目录 2菜单 3按钮）
            content.append(", 3");
            // 内容类型(1:链接,2:商品列表类型ID,3:商品详情ID,4:文章ID,5:活动ID)
            content.append(", NULL");
            // 内容信息(商品列表为商品类型ID,商品详情为商品ID,文章为文章ID,活动为活动ID)
            content.append(", NULL");
            // 菜单状态（1显示 2隐藏）
            content.append(", 1");
            // 菜单状态（1正常 2停用）
            content.append(", 1");
            // 权限标识
            content.append(", '");
            content.append("~controllerUrl~/info~controllerSuffixShow~/{id}");
            content.append("'");
            // 菜单图标
            content.append(", '");
            content.append("#");
            content.append("'");
            // 其他
            content.append(", NULL, '" + creatrById + "', '" + now + "', '" + creatrById + "', '" + now + "'");
            // 结束
            content.append(");");
            content.append(StringUtil.ENTER);
        }

        // 删除按钮
        if (file.getExistId()) {
            // 字段
            content.append(field);
            content.append(StringUtil.ENTER);
            // 值
            content.append("VALUES ('");
            // ID
            content.append(IdWorker.getIdStr());
            content.append("'");
            // 名称
            content.append(", '");
            content.append("~classComment~删除");
            content.append("'");
            // 上级菜单ID
            content.append(", '");
            content.append(idTwo);
            content.append("'");
            // 排序
            content.append(", 5");
            // 请求地址
            content.append(", NULL");
            // 路由地址
            content.append(", NULL");
            // 是否为外链（1是2否）
            content.append(", 2");
            // 是否缓存（1缓存 2不缓存）
            content.append(", 1");
            // 菜单环境(web_admin:后台管理员,web_merchant:后台商户,app_user:App用户,xcx_user:小程序用户)
            content.append(", '");
            content.append(EEnvironmentUserType.WEB_ADMIN.getCode());
            content.append("'");
            // 菜单类型（1目录 2菜单 3按钮）
            content.append(", 3");
            // 内容类型(1:链接,2:商品列表类型ID,3:商品详情ID,4:文章ID,5:活动ID)
            content.append(", NULL");
            // 内容信息(商品列表为商品类型ID,商品详情为商品ID,文章为文章ID,活动为活动ID)
            content.append(", NULL");
            // 菜单状态（1显示 2隐藏）
            content.append(", 1");
            // 菜单状态（1正常 2停用）
            content.append(", 1");
            // 权限标识
            content.append(", '");
            content.append("~controllerUrl~/remove~controllerSuffixDo~");
            content.append("'");
            // 菜单图标
            content.append(", '");
            content.append("#");
            content.append("'");
            // 其他
            content.append(", NULL, '" + creatrById + "', '" + now + "', '" + creatrById + "', '" + now + "'");
            // 结束
            content.append(");");
            content.append(StringUtil.ENTER);
        }
        return content.substring(0, content.length() - StringUtil.ENTER.length());
    }

    /**
     * 获取vue页面
     * 
     * @return
     */
    public String getVue() {
        String content = template.getContent();
        StringBuilder stringBuilder = null;
        StringBuilder options = new StringBuilder();
        StringBuilder dateRange = new StringBuilder();
        StringBuilder queryParamInput = new StringBuilder();
        StringBuilder showList = new StringBuilder();
        if (file.getExistId()) {
            showList.append("      <el-table-column type=\"selection\" width=\"55\"></el-table-column>")
                .append(StringUtil.ENTER);
        }
        Map<String, Set<String>> importPackages = new HashMap<>(10);
        Set<String> enums = new HashSet<>();
        StringBuilder enumsStr = new StringBuilder();
        StringBuilder importPackage = new StringBuilder();
        StringBuilder dicts = new StringBuilder();
        StringBuilder formInput = new StringBuilder();
        StringBuilder queryParams = new StringBuilder();
        StringBuilder rules = new StringBuilder();
        StringBuilder form = new StringBuilder();
        if (file.getExistId()) {
            form.append("        " + file.getJavaIdNameX() + ": undefined,").append(StringUtil.ENTER);
        }

        List<CodeGenFieldProperties> feilds = file.getFileFeild();
        for (CodeGenFieldProperties feild : feilds) {
            // 字典列表
            boolean isDictType = StringUtil.isNotBlankString(feild.getDictType());
            if (isDictType) {
                options.append(StringUtil.ENTER).append("      // ~fieldComment~数据字典");
                options.append(StringUtil.ENTER).append("      ~fieldNameX~Options: [],");
                dicts.append(StringUtil.ENTER)
                    .append("    this.getDicts(\"" + feild.getDictType() + "\").then(response => {");
                if (CodeGenUtil.arraysContains(CodeGenConstant.COLUMNTYPE_NUMBER,
                    feild.getFieldDatabaseType().toLowerCase())) {
                    dicts.append(StringUtil.ENTER).append("      response.data.forEach(element => {");
                    dicts.append(StringUtil.ENTER).append("        element.val = parseInt(element.val)");
                    dicts.append(StringUtil.ENTER).append("      });");
                }
                dicts.append(StringUtil.ENTER).append("      this.~fieldNameX~Options = response.data;");
                dicts.append(StringUtil.ENTER).append("    });");
                options = new StringBuilder(CodeGenReadTemplate.replacePropertyPlaceholder(options.toString(), feild));
                dicts = new StringBuilder(CodeGenReadTemplate.replacePropertyPlaceholder(dicts.toString(), feild));
            }
            // 查询参数
            String htmlType = feild.getHtmlType();
            if (EGeneralYesNo.YES.getCode() == feild.getIsQuery()) {
                if (ECodeGenHtmlType.INPUT.getCode().equals(htmlType)) {
                    queryParamInput.append("      <el-form-item label=\"~fieldComment~\" prop=\"~fieldNameX~\">")
                        .append(StringUtil.ENTER);
                    queryParamInput.append("        <el-input").append(StringUtil.ENTER);
                    queryParamInput.append("          v-model=\"queryParams.~fieldNameX~\"").append(StringUtil.ENTER);
                    queryParamInput.append("          placeholder=\"请输入~fieldComment~\"").append(StringUtil.ENTER);
                    queryParamInput.append("          clearable").append(StringUtil.ENTER);
                    queryParamInput.append("          size=\"small\"").append(StringUtil.ENTER);
                    queryParamInput.append("          style=\"width: 240px\"").append(StringUtil.ENTER);
                    queryParamInput.append("          @keyup.enter.native=\"handleQuery\"").append(StringUtil.ENTER);
                    queryParamInput.append("        />").append(StringUtil.ENTER);
                    queryParamInput.append("      </el-form-item>").append(StringUtil.ENTER);
                } else if (ECodeGenHtmlType.SELECT.getCode().equals(htmlType)) {
                    queryParamInput.append("      <el-form-item label=\"~fieldComment~\" prop=\"~fieldNameX~\">")
                        .append(StringUtil.ENTER);
                    queryParamInput.append(
                        "        <el-select v-model=\"queryParams.~fieldNameX~\" placeholder=\"~fieldComment~\" clearable size=\"small\">")
                        .append(StringUtil.ENTER);
                    if (isDictType) {
                        queryParamInput.append("          <el-option").append(StringUtil.ENTER);
                        queryParamInput.append("            v-for=\"dict in ~fieldNameX~Options\"")
                            .append(StringUtil.ENTER);
                        queryParamInput.append("            :key=\"dict.id\"").append(StringUtil.ENTER);
                        queryParamInput.append("            :label=\"dict.name\"").append(StringUtil.ENTER);
                        queryParamInput.append("            :value=\"dict.val\"").append(StringUtil.ENTER);
                        queryParamInput.append("          />").append(StringUtil.ENTER);
                    } else {
                        queryParamInput.append("          <el-option label=\"请选择字典生成\" value=\"\" />")
                            .append(StringUtil.ENTER);
                    }
                    queryParamInput.append("        </el-select>").append(StringUtil.ENTER);
                    queryParamInput.append("      </el-form-item>").append(StringUtil.ENTER);
                } else if (ECodeGenHtmlType.RADIO.getCode().equals(htmlType)) {
                    queryParamInput.append("      <el-form-item label=\"~fieldComment~\" prop=\"~fieldNameX~\">")
                        .append(StringUtil.ENTER);
                    queryParamInput.append(
                        "        <el-select v-model=\"queryParams.~fieldNameX~\" placeholder=\"~fieldComment~\" clearable size=\"small\">")
                        .append(StringUtil.ENTER);
                    if (isDictType) {
                        queryParamInput.append("          <el-option").append(StringUtil.ENTER);
                        queryParamInput.append("            v-for=\"dict in ~fieldNameX~Options\"")
                            .append(StringUtil.ENTER);
                        queryParamInput.append("            :key=\"dict.id\"").append(StringUtil.ENTER);
                        queryParamInput.append("            :label=\"dict.name\"").append(StringUtil.ENTER);
                        queryParamInput.append("            :value=\"dict.val\"").append(StringUtil.ENTER);
                        queryParamInput.append("          />").append(StringUtil.ENTER);
                    } else {
                        queryParamInput.append("          <el-option label=\"请选择字典生成\" value=\"\" />")
                            .append(StringUtil.ENTER);
                    }
                    queryParamInput.append("        </el-select>").append(StringUtil.ENTER);
                    queryParamInput.append("      </el-form-item>").append(StringUtil.ENTER);
                } else if (properties.getSystem().getCreateTime().equals(feild.getFieldNameX())) {
                    queryParamInput.append("      <el-form-item label=\"~fieldComment~\" prop=\"~fieldNameX~\">")
                        .append(StringUtil.ENTER);
                    queryParamInput.append("        <el-date-picker").append(StringUtil.ENTER);
                    queryParamInput.append("          v-model=\"dateRange\"").append(StringUtil.ENTER);
                    queryParamInput.append("          size=\"small\"").append(StringUtil.ENTER);
                    queryParamInput.append("          style=\"width: 240px\"").append(StringUtil.ENTER);
                    queryParamInput.append("          value-format=\"yyyy-MM-dd\"").append(StringUtil.ENTER);
                    queryParamInput.append("          type=\"daterange\"").append(StringUtil.ENTER);
                    queryParamInput.append("          range-separator=\"-\"").append(StringUtil.ENTER);
                    queryParamInput.append("          start-placeholder=\"开始日期\"").append(StringUtil.ENTER);
                    queryParamInput.append("          end-placeholder=\"结束日期\"").append(StringUtil.ENTER);
                    queryParamInput.append("        ></el-date-picker>").append(StringUtil.ENTER);
                    queryParamInput.append("      </el-form-item>").append(StringUtil.ENTER);
                    dateRange.append(StringUtil.ENTER).append("      // 日期范围");
                    dateRange.append(StringUtil.ENTER).append("      dateRange: [],");
                }
                queryParamInput = new StringBuilder(
                    CodeGenReadTemplate.replacePropertyPlaceholder(queryParamInput.toString(), feild));
                queryParams.append(StringUtil.ENTER).append("        ~fieldNameX~: undefined,");
                queryParams =
                    new StringBuilder(CodeGenReadTemplate.replacePropertyPlaceholder(queryParams.toString(), feild));
            }
            // 表格数据
            if (EGeneralYesNo.YES.getCode() == feild.getIsList()) {
                if (isDictType) {
                    showList.append(
                        "      <el-table-column label=\"~fieldComment~\" align=\"center\" prop=\"~fieldNameX~\" :show-overflow-tooltip=\"true\" :formatter=\"~fieldNameX~Format\" />")
                        .append(StringUtil.ENTER);
                } else {
                    showList.append(
                        "      <el-table-column label=\"~fieldComment~\" align=\"center\" prop=\"~fieldNameX~\" :show-overflow-tooltip=\"true\" />")
                        .append(StringUtil.ENTER);
                }
                showList =
                    new StringBuilder(CodeGenReadTemplate.replacePropertyPlaceholder(showList.toString(), feild));
            }
            // 表单校验
            if (EGeneralYesNo.YES.getCode() == feild.getIsRequired()) {
                rules.append("        ~fieldNameX~: [").append(StringUtil.ENTER);
                rules.append("          { required: true, message: \"请输入~fieldComment~\", trigger: \"blur\" }")
                    .append(StringUtil.ENTER);
                rules.append("        ],").append(StringUtil.ENTER);
                rules = new StringBuilder(CodeGenReadTemplate.replacePropertyPlaceholder(rules.toString(), feild));
            }

            // 下面是字段的添加和修改
            if (EGeneralYesNo.YES.getCode() == feild.getIsAdd()) {

            }
            if (EGeneralYesNo.YES.getCode() == feild.getIsEdit()) {

            }
            // 导入包
            if (ECodeGenHtmlType.EDITOR.getCode().equals(htmlType)) {
                importPackage.append(StringUtil.ENTER).append("import Editor from '@/components/Editor';");
            }
            if (ECodeGenHtmlType.UPLOAD_IMAGE.getCode().equals(htmlType)) {
                Set<String> set = importPackages.get(" } from \"@/enum/enum\";");
                if (set == null) {
                    set = new HashSet<>();
                    importPackages.put(" } from \"@/enum/enum\";", set);
                }
                set.add("FILE_TYPE");
                enums.add(StringUtil.ENTER + "      // 文件类型" + StringUtil.ENTER + "      eFileType: FILE_TYPE,");
            }
            // 表单重置
            if (EGeneralYesNo.YES.getCode() == feild.getIsAdd() || EGeneralYesNo.YES.getCode() == feild.getIsEdit()) {
                form.append("        ~fieldNameX~: undefined,").append(StringUtil.ENTER);
                form = new StringBuilder(CodeGenReadTemplate.replacePropertyPlaceholder(form.toString(), feild));

                // form表单
                formInput.append("        <el-form-item label=\"~fieldComment~\" prop=\"~fieldNameX~\">")
                    .append(StringUtil.ENTER);
                if (ECodeGenHtmlType.INPUT.getCode().equals(htmlType)) {
                    formInput
                        .append(
                            "          <el-input v-model=\"form.~fieldNameX~\" placeholder=\"请输入~fieldComment~\" />")
                        .append(StringUtil.ENTER);
                } else if (ECodeGenHtmlType.TEXTAREA.getCode().equals(htmlType)) {
                    formInput.append(
                        "          <el-input v-model=\"form.~fieldNameX~\" type=\"textarea\" placeholder=\"请输入~fieldComment~\" />")
                        .append(StringUtil.ENTER);
                } else if (ECodeGenHtmlType.SELECT.getCode().equals(htmlType)) {
                    formInput.append(
                        "          <el-select v-model=\"form.~fieldNameX~\" placeholder=\"~fieldComment~\" clearable size=\"small\">")
                        .append(StringUtil.ENTER);
                    if (isDictType) {
                        formInput.append("            <el-option").append(StringUtil.ENTER);
                        formInput.append("              v-for=\"dict in ~fieldNameX~Options\"")
                            .append(StringUtil.ENTER);
                        formInput.append("              :key=\"dict.id\"").append(StringUtil.ENTER);
                        formInput.append("              :label=\"dict.name\"").append(StringUtil.ENTER);
                        formInput.append("              :value=\"dict.val\"").append(StringUtil.ENTER);
                        formInput.append("            />").append(StringUtil.ENTER);
                    } else {
                        formInput.append("            <el-option label=\"请选择字典生成\" value=\"\" />")
                            .append(StringUtil.ENTER);
                    }
                    formInput.append("          </el-select>").append(StringUtil.ENTER);
                } else if (ECodeGenHtmlType.RADIO.getCode().equals(htmlType)) {
                    formInput.append("          <el-radio-group v-model=\"form.~fieldNameX~\">")
                        .append(StringUtil.ENTER);
                    if (isDictType) {
                        formInput.append("            <el-radio").append(StringUtil.ENTER);
                        formInput.append("              v-for=\"dict in ~fieldNameX~Options\"")
                            .append(StringUtil.ENTER);
                        formInput.append("              :key=\"dict.id\"").append(StringUtil.ENTER);
                        formInput.append("              :label=\"dict.val\"").append(StringUtil.ENTER);
                        formInput.append("            >{{dict.name}}</el-radio>").append(StringUtil.ENTER);
                    } else {
                        formInput.append("            <el-radio label=\"1\">请选择字典生成</el-radio>")
                            .append(StringUtil.ENTER);
                    }
                    formInput.append("          </el-radio-group>").append(StringUtil.ENTER);
                } else if (ECodeGenHtmlType.CHECKBOX.getCode().equals(htmlType)) {
                    formInput.append("          <el-checkbox-group v-model=\"form.~fieldNameX~\">")
                        .append(StringUtil.ENTER);
                    if (isDictType) {
                        formInput.append("            <el-checkbox").append(StringUtil.ENTER);
                        formInput.append("              v-for=\"dict in ~fieldNameX~Options\"")
                            .append(StringUtil.ENTER);
                        formInput.append("              :key=\"dict.id\"").append(StringUtil.ENTER);
                        formInput.append("              :label=\"dict.val\">").append(StringUtil.ENTER);
                        formInput.append("              {{dict.name}}").append(StringUtil.ENTER);
                    } else {
                        formInput.append("            <el-checkbox>请选择字典生成</el-checkbox>").append(StringUtil.ENTER);
                    }
                    formInput.append("          </el-checkbox-group>").append(StringUtil.ENTER);
                } else if (ECodeGenHtmlType.DATETIME.getCode().equals(htmlType)) {
                    formInput.append("          <el-date-picker clearable size=\"small\" style=\"width: 200px\"")
                        .append(StringUtil.ENTER);
                    formInput.append("            v-model=\"form.~fieldNameX~\"").append(StringUtil.ENTER);
                    formInput.append("            type=\"date\"").append(StringUtil.ENTER);
                    formInput.append("            value-format=\"yyyy-MM-dd\"").append(StringUtil.ENTER);
                    formInput.append("            placeholder=\"选择~fieldComment~\">").append(StringUtil.ENTER);
                    formInput.append("          </el-date-picker>").append(StringUtil.ENTER);
                } else if (ECodeGenHtmlType.UPLOAD_IMAGE.getCode().equals(htmlType)) {
                    formInput
                        .append("          <uploadImage :type=\"[eFileType.FILE]\" v-model=\"form.~fieldNameX~\"/>")
                        .append(StringUtil.ENTER);
                } else if (ECodeGenHtmlType.EDITOR.getCode().equals(htmlType)) {
                    formInput.append("          <editor v-model=\"form.~fieldNameX~\" :min-height=\"192\"/>")
                        .append(StringUtil.ENTER);
                }
                formInput.append("        </el-form-item>").append(StringUtil.ENTER);
                formInput =
                    new StringBuilder(CodeGenReadTemplate.replacePropertyPlaceholder(formInput.toString(), feild));
            }
        }
        // 导入包
        if (importPackages.size() > 0) {
            Set<Entry<String, Set<String>>> entrySet = importPackages.entrySet();
            for (Entry<String, Set<String>> entry : entrySet) {
                importPackage.append(StringUtil.ENTER).append("import { ");
                Set<String> value = entry.getValue();
                for (String pk : value) {
                    importPackage.append(pk).append(", ");
                }
                importPackage = new StringBuilder(importPackage.substring(0, importPackage.length() - ", ".length()));
                importPackage.append(entry.getKey());
            }
        }
        content = content.replace("~import~", importPackage.toString());
        // 枚举值
        for (String e : enums) {
            enumsStr.append(e);
        }
        content = content.replace("~enum~", enumsStr.toString());
        // 字典列表
        content = content.replace("~options~", options.toString());
        content = content.replace("~dicts~", dicts.toString());
        // 表格数据
        if (showList.length() > 0) {
            showList = showList.replace(showList.length() - StringUtil.ENTER.length(), showList.length(), "");
        }
        content = content.replace("~showList~", showList.toString());
        // 表单校验
        if (rules.length() > 0) {
            rules = rules.replace(rules.length() - 1 - StringUtil.ENTER.length(), rules.length(), "");
        }
        content = content.replace("~rules~", rules.toString());
        // 查询input框
        if (queryParamInput.length() > 0) {
            queryParamInput = queryParamInput.replace(queryParamInput.length() - StringUtil.ENTER.length(),
                queryParamInput.length(), "");
        }
        content = content.replace("~queryParamInput~", queryParamInput.toString());
        // 时间区间参数
        content = content.replace("~dateRange~", dateRange.toString());
        // 查询参数
        if (queryParams.length() > 0) {
            queryParams = queryParams.replace(queryParams.length() - 1, queryParams.length(), "");
        }
        content = content.replace("~queryParams~", queryParams.toString());
        // 表单
        if (formInput.length() > 0) {
            formInput = formInput.replace(formInput.length() - StringUtil.ENTER.length(), formInput.length(), "");
        }
        content = content.replace("~formInput~", formInput.toString());
        // 表单重置
        if (form.length() > 0) {
            form = form.replace(form.length() - 1 - StringUtil.ENTER.length(), form.length(), "");
        }
        content = content.replace("~form~", form.toString());

        // 按钮
        stringBuilder = new StringBuilder();
        stringBuilder.append("      <el-col :span=\"1.5\">").append(StringUtil.ENTER);
        stringBuilder.append("        <el-button").append(StringUtil.ENTER);
        stringBuilder.append("          type=\"primary\"").append(StringUtil.ENTER);
        stringBuilder.append("          icon=\"el-icon-plus\"").append(StringUtil.ENTER);
        stringBuilder.append("          size=\"mini\"").append(StringUtil.ENTER);
        stringBuilder.append("          @click=\"handleAdd\"").append(StringUtil.ENTER);
        stringBuilder.append("          v-hasPermi=\"['~controllerUrl~/save~controllerSuffixDo~']\"")
            .append(StringUtil.ENTER);
        stringBuilder.append("        >新增</el-button>").append(StringUtil.ENTER);
        stringBuilder.append("      </el-col>").append(StringUtil.ENTER);
        if (file.getExistId()) {
            stringBuilder.append("      <el-col :span=\"1.5\">").append(StringUtil.ENTER);
            stringBuilder.append("        <el-button").append(StringUtil.ENTER);
            stringBuilder.append("          type=\"success\"").append(StringUtil.ENTER);
            stringBuilder.append("          icon=\"el-icon-edit\"").append(StringUtil.ENTER);
            stringBuilder.append("          size=\"mini\"").append(StringUtil.ENTER);
            stringBuilder.append("          :disabled=\"single\"").append(StringUtil.ENTER);
            stringBuilder.append("          @click=\"handleUpdate\"").append(StringUtil.ENTER);
            stringBuilder.append("          v-hasPermi=\"['~controllerUrl~/updateById~controllerSuffixDo~']\"")
                .append(StringUtil.ENTER);
            stringBuilder.append("        >修改</el-button>").append(StringUtil.ENTER);
            stringBuilder.append("      </el-col>").append(StringUtil.ENTER);
            stringBuilder.append("      <el-col :span=\"1.5\">").append(StringUtil.ENTER);
            stringBuilder.append("        <el-button").append(StringUtil.ENTER);
            stringBuilder.append("          type=\"danger\"").append(StringUtil.ENTER);
            stringBuilder.append("          icon=\"el-icon-delete\"").append(StringUtil.ENTER);
            stringBuilder.append("          size=\"mini\"").append(StringUtil.ENTER);
            stringBuilder.append("          :disabled=\"multiple\"").append(StringUtil.ENTER);
            stringBuilder.append("          @click=\"handleDelete\"").append(StringUtil.ENTER);
            stringBuilder.append("          v-hasPermi=\"['~controllerUrl~/remove~controllerSuffixDo~/{id}']\"")
                .append(StringUtil.ENTER);
            stringBuilder.append("        >删除</el-button>").append(StringUtil.ENTER);
            stringBuilder.append("      </el-col>").append(StringUtil.ENTER);
        }
        stringBuilder.append("      <el-col :span=\"1.5\">").append(StringUtil.ENTER);
        stringBuilder.append("        <el-button").append(StringUtil.ENTER);
        stringBuilder.append("          type=\"warning\"").append(StringUtil.ENTER);
        stringBuilder.append("          icon=\"el-icon-download\"").append(StringUtil.ENTER);
        stringBuilder.append("          size=\"mini\"").append(StringUtil.ENTER);
        stringBuilder.append("          @click=\"handleExport\"").append(StringUtil.ENTER);
        stringBuilder.append("          v-hasPermi=\"['~controllerUrl~/export']\"").append(StringUtil.ENTER);
        stringBuilder.append("        >导出</el-button>");
        content = content.replace("~tableButton~", stringBuilder.toString());
        // 行按钮
        stringBuilder = new StringBuilder();
        if (file.getExistId()) {
            stringBuilder
                .append(
                    "      <el-table-column label=\"操作\" align=\"center\" class-name=\"small-padding fixed-width\">")
                .append(StringUtil.ENTER);
            stringBuilder.append("        <template slot-scope=\"scope\">").append(StringUtil.ENTER);
            stringBuilder.append("          <el-button").append(StringUtil.ENTER);
            stringBuilder.append("            size=\"mini\"").append(StringUtil.ENTER);
            stringBuilder.append("            type=\"text\"").append(StringUtil.ENTER);
            stringBuilder.append("            icon=\"el-icon-edit\"").append(StringUtil.ENTER);
            stringBuilder.append("            @click=\"handleUpdate(scope.row)\"").append(StringUtil.ENTER);
            stringBuilder.append("            v-hasPermi=\"['~controllerUrl~/updateById~controllerSuffixDo~']\"")
                .append(StringUtil.ENTER);
            stringBuilder.append("          >修改</el-button>").append(StringUtil.ENTER);
            stringBuilder.append("          <el-button").append(StringUtil.ENTER);
            stringBuilder.append("            size=\"mini\"").append(StringUtil.ENTER);
            stringBuilder.append("            type=\"text\"").append(StringUtil.ENTER);
            stringBuilder.append("            icon=\"el-icon-delete\"").append(StringUtil.ENTER);
            stringBuilder.append("            @click=\"handleDelete(scope.row)\"").append(StringUtil.ENTER);
            stringBuilder.append("            v-hasPermi=\"['~controllerUrl~/remove~controllerSuffixDo~/{id}']\"")
                .append(StringUtil.ENTER);
            stringBuilder.append("          >删除</el-button>").append(StringUtil.ENTER);
            stringBuilder.append("        </template>").append(StringUtil.ENTER);
            stringBuilder.append("      </el-table-column>");
        }
        content = content.replace("~rowButton~", stringBuilder.toString());
        // 接口列表
        stringBuilder = new StringBuilder();
        stringBuilder.append("add~classNameD~");
        if (file.getExistId()) {
            stringBuilder.append(", update~classNameD~");
        }
        stringBuilder.append(", list~classNameD~");
        stringBuilder.append(", export~classNameD~");
        if (file.getExistId()) {
            stringBuilder.append(", get~classNameD~");
            stringBuilder.append(", del~classNameD~");
        }
        content = content.replace("~apiList~", stringBuilder.toString());
        // id参数
        stringBuilder = new StringBuilder();
        if (file.getExistId()) {
            stringBuilder.append(StringUtil.ENTER).append("      // 选中数组").append(StringUtil.ENTER);
            stringBuilder.append("      ~idX~s: [],");
        }
        content = content.replace("~selectionIds~", stringBuilder.toString());
        // 列表方法参数
        if (dateRange.length() > 0) {
            content = content.replace("~thisQueryParams~", "this.addDateRange(this.queryParams, this.dateRange)");
        } else {
            content = content.replace("~thisQueryParams~", "this.queryParams");
        }
        // 方法
        stringBuilder = new StringBuilder();
        if (file.getExistId()) {
            stringBuilder.append("    // 多选框选中数据").append(StringUtil.ENTER);
            stringBuilder.append("    handleSelectionChange(selection) {").append(StringUtil.ENTER);
            stringBuilder.append("      this.~idX~s = selection.map(item => item.~idX~)").append(StringUtil.ENTER);
            stringBuilder.append("      this.single = selection.length!=1").append(StringUtil.ENTER);
            stringBuilder.append("      this.multiple = !selection.length").append(StringUtil.ENTER);
            stringBuilder.append("    },").append(StringUtil.ENTER);
        }
        stringBuilder.append("    /** 新增按钮操作 */").append(StringUtil.ENTER);
        stringBuilder.append("    handleAdd() {").append(StringUtil.ENTER);
        stringBuilder.append("      this.reset();").append(StringUtil.ENTER);
        stringBuilder.append("      this.open = true;").append(StringUtil.ENTER);
        stringBuilder.append("      this.title = \"添加~classComment~\";").append(StringUtil.ENTER);
        stringBuilder.append("    },").append(StringUtil.ENTER);
        if (file.getExistId()) {
            stringBuilder.append("    /** 修改按钮操作 */").append(StringUtil.ENTER);
            stringBuilder.append("    handleUpdate(row) {").append(StringUtil.ENTER);
            stringBuilder.append("      this.reset();").append(StringUtil.ENTER);
            stringBuilder.append("      const ~idX~ = row.~idX~ || this.~idX~s").append(StringUtil.ENTER);
            stringBuilder.append("      get~classNameD~(~idX~).then(response => {").append(StringUtil.ENTER);
            stringBuilder.append("        this.form = response.data;").append(StringUtil.ENTER);
            stringBuilder.append("        this.open = true;").append(StringUtil.ENTER);
            stringBuilder.append("        this.title = \"修改~classComment~\";").append(StringUtil.ENTER);
            stringBuilder.append("      });").append(StringUtil.ENTER);
            stringBuilder.append("    },").append(StringUtil.ENTER);
        }
        stringBuilder.append("    /** 提交按钮 */").append(StringUtil.ENTER);
        stringBuilder.append("    submitForm: function() {").append(StringUtil.ENTER);
        stringBuilder.append("      this.$refs[\"form\"].validate(valid => {").append(StringUtil.ENTER);
        stringBuilder.append("        if (valid) {").append(StringUtil.ENTER);
        if (file.getExistId()) {
            stringBuilder.append("          if (this.form.~idX~ != undefined) {").append(StringUtil.ENTER);
            stringBuilder.append("            update~classNameD~(this.form).then(response => {")
                .append(StringUtil.ENTER);
            stringBuilder.append("              this.msgSuccess(\"修改成功\");").append(StringUtil.ENTER);
            stringBuilder.append("              this.open = false;").append(StringUtil.ENTER);
            stringBuilder.append("              this.getList();").append(StringUtil.ENTER);
            stringBuilder.append("            });").append(StringUtil.ENTER);
            stringBuilder.append("          } else {").append(StringUtil.ENTER);
            stringBuilder.append("            add~classNameD~(this.form).then(response => {").append(StringUtil.ENTER);
            stringBuilder.append("              this.msgSuccess(\"新增成功\");").append(StringUtil.ENTER);
            stringBuilder.append("              this.open = false;").append(StringUtil.ENTER);
            stringBuilder.append("              this.getList();").append(StringUtil.ENTER);
            stringBuilder.append("            });").append(StringUtil.ENTER);
            stringBuilder.append("          }").append(StringUtil.ENTER);
        } else {
            stringBuilder.append("          add~classNameD~(this.form).then(response => {").append(StringUtil.ENTER);
            stringBuilder.append("            this.msgSuccess(\"新增成功\");").append(StringUtil.ENTER);
            stringBuilder.append("            this.open = false;").append(StringUtil.ENTER);
            stringBuilder.append("            this.getList();").append(StringUtil.ENTER);
            stringBuilder.append("          });").append(StringUtil.ENTER);
        }
        stringBuilder.append("        }").append(StringUtil.ENTER);
        stringBuilder.append("      });").append(StringUtil.ENTER);
        stringBuilder.append("    },").append(StringUtil.ENTER);
        if (file.getExistId()) {
            stringBuilder.append("    /** 删除按钮操作 */").append(StringUtil.ENTER);
            stringBuilder.append("    handleDelete(row) {").append(StringUtil.ENTER);
            stringBuilder.append("      const ~idX~s = row.~idX~ || this.~idX~s").append(StringUtil.ENTER);
            stringBuilder.append("      this.$confirm('是否确认删除~classComment~编号为\"' + ~idX~s + '\"的数据项?', \"警告\", {")
                .append(StringUtil.ENTER);
            stringBuilder.append("          confirmButtonText: \"确定\",").append(StringUtil.ENTER);
            stringBuilder.append("          cancelButtonText: \"取消\",").append(StringUtil.ENTER);
            stringBuilder.append("          type: \"warning\"").append(StringUtil.ENTER);
            stringBuilder.append("        }).then(function() {").append(StringUtil.ENTER);
            stringBuilder.append("          return del~classNameD~(~idX~s);").append(StringUtil.ENTER);
            stringBuilder.append("        }).then(() => {").append(StringUtil.ENTER);
            stringBuilder.append("          this.getList();").append(StringUtil.ENTER);
            stringBuilder.append("          this.msgSuccess(\"删除成功\");").append(StringUtil.ENTER);
            stringBuilder.append("        }).catch(() => {});").append(StringUtil.ENTER);
            stringBuilder.append("    },").append(StringUtil.ENTER);
        }
        stringBuilder.append("    /** 导出按钮操作 */").append(StringUtil.ENTER);
        stringBuilder.append("    handleExport() {").append(StringUtil.ENTER);
        stringBuilder.append("      const queryParams = this.addDateRange(this.queryParams, this.dateRange);")
            .append(StringUtil.ENTER);
        stringBuilder.append("      this.$confirm('是否确认导出所有参数数据项?', \"警告\", {").append(StringUtil.ENTER);
        stringBuilder.append("          confirmButtonText: \"确定\",").append(StringUtil.ENTER);
        stringBuilder.append("          cancelButtonText: \"取消\",").append(StringUtil.ENTER);
        stringBuilder.append("          type: \"warning\"").append(StringUtil.ENTER);
        stringBuilder.append("        }).then(function() {").append(StringUtil.ENTER);
        stringBuilder.append("          return exportConfig(queryParams);").append(StringUtil.ENTER);
        stringBuilder.append("        }).catch(() => {});").append(StringUtil.ENTER);
        stringBuilder.append("    }");
        content = content.replace("~handle~", stringBuilder.toString());
        return content;
    }

    /**
     * 获取类的路径
     * 
     * @param cla
     * @return
     */
    private static String getClassPackage(Class<?> cla) {
        return cla.getName();
    }

}